/*
 * SerializeBasic.cpp
 *
 *  Created on: Dec 6, 2024
 *      Author: zhian
 */
#include "SerializeBasic.h"


nlohmann::json serializeAffine3d(const Eigen::Affine3d& affine)
{
    nlohmann::json matrixJson;
    for (int i = 0; i < affine.matrix().rows(); ++i) {
        for (int j = 0; j < affine.matrix().cols(); ++j) {
            matrixJson[i][j] = affine.matrix()(i, j);
        }
    }
    return matrixJson;
}

Eigen::Affine3d deserializeAffine3d(const nlohmann::json& js) {
	Eigen::Affine3d affine;
	for (int i = 0; i < affine.matrix().rows(); ++i) {
		for (int j = 0; j < affine.matrix().cols(); ++j) {
			affine.matrix()(i, j) = js[i][j].get<double>();
		}
	}
	return affine;
}


std::vector<MJointData> DMHStruct::MH2Vec(const MHS &mh)
{
    std::vector<MJointData> ret;
    for(auto &c:mh){
        int partID = c.partID;
        int ChainID = c.ChainID;
        for(auto &cd:c.mj){
            ret.push_back(cd);
        }
    }
    return ret;
}

std::vector<MJointData> DMHStruct::OPH2Vec(const OPH &op)
{
    std::vector<MJointData> ret;
    for(auto &c:op.mj){
       ret.push_back(c);
    }
    return ret;
}
